const fs = require('fs')
const path = require('path')
function bfs(dir) {
    const stack = []
    if (fs.statSync(dir).isDirectory()) {
        const dirs = fs.readdirSync(path.resolve(__dirname, dir)) 
        dirs.forEach(filename => {
            stack.push(dir + path.sep+filename)
        })
        while (stack.length) {
            const item = stack.shift()
            if (path.extname(item) === '.js') {
                console.log(item);
            }
            if (fs.statSync(item).isDirectory()) {
                const dirs = fs.readdirSync(path.resolve(__dirname, item)) 
                dirs.forEach(filename => {
                    stack.push(item + path.sep+filename)
                })
            }
        }
    }
}
let result = bfs(path.resolve(__dirname, '1'))
console.log(JSON.stringify(result));